package net.maxwoods.nimble.websocket;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class MainWindow extends Application {

    private WebSocketServer webSocketServer=new WebSocketServer();

    public static void main(String[] args) {
        Application.launch(MainWindow.class,args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        Parent root= FXMLLoader.load(getClass().getResource("/main.fxml"));
        Scene scene=new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Websocket Server");
        primaryStage.show();
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                webSocketServer.stop();
                System.out.print("监听到窗口关闭");
            }
        });
        webSocketServer.Start();
    }
}
